package edu.scau.mis.pos.service.impl;

import edu.scau.mis.core.utils.DateUtils;
import edu.scau.mis.pos.entity.OrderItem;
import edu.scau.mis.pos.entity.PosItem;
import edu.scau.mis.pos.entity.PosOrder;
import edu.scau.mis.pos.mapper.PosOrderMapper;
import edu.scau.mis.pos.service.IPosOrderService;
import edu.scau.mis.pos.vo.OrderItemVo;
import edu.scau.mis.pos.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 订单表(PosOrder)表服务实现类
 *
 * @author CJW
 * @since 2021-11-08 21:22:02
 */
@ComponentScan
@Service("posOrderService")
public class PosOrderServiceImpl implements IPosOrderService {
    @Resource
    private PosOrderMapper posOrderMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param orderId 主键
     * @return 实例对象
     */
    @Override
    public PosOrder queryById(Integer orderId) {
        return this.posOrderMapper.queryById(orderId);
    }

    /**
     * 查询指定行
     *
     * @param posOrder 筛选条件
     * @return 查询结果
     */
    @Override
    public List<PosOrder> queryAll(PosOrder posOrder) {
        return this.posOrderMapper.queryAll(posOrder);
    }

    /**
     * 新增数据
     *
     * @param posOrder 实例对象
     * @return 实例对象
     */
    @Override
    public PosOrder insert(PosOrder posOrder) {
        this.posOrderMapper.insert(posOrder);
        return posOrder;
    }

    /**
     * 修改数据
     *
     * @param posOrder 实例对象
     * @return 实例对象
     */
    @Override
    public PosOrder update(PosOrder posOrder) {
        this.posOrderMapper.update(posOrder);
        return this.queryById(posOrder.getOrderId());
    }

    /**
     * 通过主键删除数据
     *
     * @param orderId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer orderId) {

        return this.posOrderMapper.deleteById(orderId) > 0;
    }

    /**
     * 新增数据
     *
     * @param
     * @return 实例对象

    @Override
    public PosOrder insertOrder(OrderVo orderVo) {
        StringBuffer sb = new StringBuffer();
        sb.append("so_");
        DateUtils dateUtils = new DateUtils();
        String nowDate = dateUtils.getNowDate().toString();
        sb.append(nowDate);
        orderVo.setOrderNo(sb.toString());
        orderVo.setSaleDatetime(nowDate);
        String orderNo = orderVo.getOrderNo();
        String saleDatetime = orderVo.getSaleDatetime();
        PosOrder posOrder = new PosOrder();
        posOrder.setOrderNo(orderNo);
        posOrder.setSaleDatetime(saleDatetime);
        this.posOrderMapper.insert(posOrder);
        return posOrder;
    }
     */
    @Override
    public PosOrder insertOrder() {
        StringBuffer sb = new StringBuffer();
        sb.append("so_");
        DateUtils dateUtils = new DateUtils();
        String date = dateUtils.getOrderTime();
        String nowDate = dateUtils.saleOrderTime();
        sb.append(date);
        PosOrder posOrder = new PosOrder();
        posOrder.setOrderNo(sb.toString());
        posOrder.setSaleDatetime(nowDate);
        this.posOrderMapper.insert(posOrder);
        return posOrder;
    }

}
